<template>
  <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
          <el-form-item label="用户名" prop="mobileUserId">
            <el-input
              v-model="queryParams.mobileUserId"
              placeholder="请输入用户"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
    <!--      <el-form-item label="瞬间类型0-图片 1-视频(数据字典)" prop="momentType">-->
    <!--        <el-select v-model="queryParams.momentType" placeholder="请选择瞬间类型0-图片 1-视频(数据字典)" clearable size="small">-->
    <!--          <el-option label="请选择字典生成" value="" />-->
    <!--        </el-select>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="名称" prop="name">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.name"-->
    <!--          placeholder="请输入名称"-->
    <!--          clearable-->
    <!--          size="small"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        />-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="视频截图图片地址" prop="videoUrl">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.videoUrl"-->
    <!--          placeholder="请输入视频截图图片地址"-->
    <!--          clearable-->
    <!--          size="small"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        />-->
    <!--      </el-form-item>-->
    <!--      <el-form-item>-->
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
    <!--      </el-form-item>-->
        </el-form>






    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="primary"-->
    <!--          icon="el-icon-plus"-->
    <!--          size="mini"-->
    <!--          @click="handleAdd"-->
    <!--          v-hasPermi="['system:dynamic:add']"-->
    <!--        >新增</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="success"-->
    <!--          icon="el-icon-edit"-->
    <!--          size="mini"-->
    <!--          :disabled="single"-->
    <!--          @click="handleUpdate"-->
    <!--          v-hasPermi="['system:dynamic:edit']"-->
    <!--        >修改</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="danger"-->
    <!--          icon="el-icon-delete"-->
    <!--          size="mini"-->
    <!--          :disabled="multiple"-->
    <!--          @click="handleDelete"-->
    <!--          v-hasPermi="['system:dynamic:remove']"-->
    <!--        >删除</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="warning"-->
    <!--          icon="el-icon-download"-->
    <!--          size="mini"-->
    <!--          @click="handleExport"-->
    <!--          v-hasPermi="['system:dynamic:export']"-->
    <!--        >导出</el-button>-->
    <!--      </el-col>-->
    <!--    </el-row>-->






    <el-table v-loading="loading" :data="dynamicList" >
      <el-table-column label="用户名" align="center" prop="createBy" />
      <el-table-column label="动态名称" align="center" prop="name" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="点赞数" align="center" prop="pariseTotal" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleParise(scope.row)">{{scope.row.pariseTotal}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="评论数" align="center" prop="commentTotal" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleComment(scope.row)">{{scope.row.commentTotal}}</el-button>
        </template>
      </el-table-column>
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-edit"-->
      <!--            @click="handleUpdate(scope.row)"-->
      <!--            v-hasPermi="['system:dynamic:edit']"-->
      <!--          >修改</el-button>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-delete"-->
      <!--            @click="handleDelete(scope.row)"-->
      <!--            v-hasPermi="['system:dynamic:remove']"-->
      <!--          >删除</el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改动态对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="mobileUserId">
          <el-input v-model="form.mobileUserId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="瞬间类型0-图片 1-视频(数据字典)">
          <el-select v-model="form.momentType" placeholder="请选择瞬间类型0-图片 1-视频(数据字典)">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="详情" prop="detail">
          <el-input v-model="form.detail" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="视频截图图片地址" prop="videoUrl">
          <el-input v-model="form.videoUrl" placeholder="请输入视频截图图片地址" />
        </el-form-item>
        <el-form-item label="视频截图图片地址" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入视频截图图片地址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 评论对话框 -->
    <el-dialog :title="title"  :visible.sync="openComment"  width="800px" @close='closeDialog'>
      <el-table v-loading="loading" :data="commentList" >
        <el-table-column label="名称" align="center" prop="userName" />
        <el-table-column label="内容" align="center" prop="value" />
        <el-table-column label="创建时间" align="center" prop="createDate" />
        <el-table-column label="操作是否展示" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleCommentOperate(scope.row)"
              v-hasPermi="['system:dynamic:edit']"
            >{{scope.row.delFlag=="1"?"展示":"隐藏"}}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="commentTotal>0"
        :total="commentTotal"
        :page.sync="commentQueryParams.pageNum"
        :limit.sync="commentQueryParams.pageSize"
        @pagination="handleCommentPaper"
      />
    </el-dialog>
    <!-- 点赞对话框 -->
    <el-dialog :title="title"  :visible.sync="openParise"  width="800px" @close='closeDialog'>
      <el-table v-loading="loading" :data="pariseList" >
        <el-table-column label="名称" align="center" prop="userName" />
        <el-table-column label="点赞时间" align="center" prop="createDate" />
      </el-table>
      <pagination
        v-show="pariseTotal>0"
        :total="pariseTotal"
        :page.sync="pariseQueryParams.pageNum"
        :limit.sync="pariseQueryParams.pageSize"
        @pagination="handleParisePaper"
      />
    </el-dialog>
  </div>
</template>

<script>
  import { listDynamic, getDynamic, delDynamic, addDynamic, updateDynamic, exportDynamic } from "@/api/system/dynamic/dynamic";
  import {getParise } from "@/api/system/dynamic/parise";
  import {getComment ,updateComment } from "@/api/system/dynamic/comment";
  export default {
    name: "Dynamic",
    data() {
      return {

        //评论详情 查询参数
        commentQueryParams: {
          dynamicId: null,
          pageNum: 1,
          pageSize: 10
        },
        handleCommentItem:{},
        //点赞详情 查询参数
        pariseQueryParams: {
          dynamicId: null,
          pageNum: 1,
          pageSize: 10
        },
        handlePariseItem:{},

        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        commentTotal:0,
        pariseTotal:0,
        // 动态表格数据
        dynamicList: [],
        // 评论表格数据
        commentList: [],
        // 点赞表格数据
        pariseList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 是否显示评论弹出层
        openComment: false,
        // 是否显示点赞弹出层
        openParise: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          mobileUserId: undefined,
          momentType: undefined,
          name: undefined,
          detail: undefined,
          videoUrl: undefined,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      //关闭对话框
      // @close='closeDialog'
      closeDialog(){
        this.open  = false
        this.openComment  = false
        this.openParise  = false
        // this.changeType = true
        this.reset();
        // if (!!this.$refs.uploadImg) this.$refs.uploadImg.clearFiles()
      },
      //点击表格评论
      handleComment(e){
        // console.log('表格评论',e)
        this.handleCommentItem = e
        // console.log('表格评论',e)
        this.commentQueryParams.dynamicId = e.dynamicId
        console.log(this.commentQueryParams)
        getComment(this.commentQueryParams).then(res=>{
          console.log('表格评论详细信息',res)
          this.commentList = res.rows
          this.commentTotal = res.total;
          this.openComment=true
          this.title = "评论详情"
        })
      },
      //评论分页
      handleCommentPaper(){
        var e =  this.handleCommentItem
        this.commentQueryParams.dynamicId = e.dynamicId
        console.log(this.commentQueryParams)
        getComment(this.commentQueryParams).then(res=>{
          console.log('表格评论详细信息',res)
          this.commentList = res.rows
          this.commentTotal = res.total;
          this.openComment=true
          this.title = "评论详情"
        })
      },
      //评论操作展示
      handleCommentOperate(e){
        console.log(e)
        if (e.delFlag=="1" ){
          e.delFlag="0"
        }else if(e.delFlag=="0" ){
          e.delFlag="1"
        }
        updateComment(e).then(res=>{
          console.log(res)
        })
      },
      //点击表格点赞
      handleParise(e){
        // console.log('表格点赞',e)
        this.handlePariseItem = e
        this.pariseQueryParams.dynamicId = e.dynamicId
        getParise(this.pariseQueryParams).then(res=>{
          console.log('表格点赞详细信息',res)
          this.pariseList = res.rows
          this.pariseTotal = res.total;
          this.openParise=true
          this.title = "点赞详情"
        })
      },
      //点赞分页
      handleParisePaper(){
        var e =  this.handlePariseItem
        this.pariseQueryParams.dynamicId = e.dynamicId
        getParise(this.pariseQueryParams).then(res=>{
          console.log('表格点赞详细信息',res)
          this.pariseList = res.rows
          this.pariseTotal = res.total;
          this.openParise=true
          this.title = "点赞详情"
        })
      },
      /** 查询动态列表 */
      getList() {
        this.loading = true;
        listDynamic(this.queryParams).then(response => {
          console.log('查询动态列表',response)
          this.dynamicList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          dynamicId: undefined,
          mobileUserId: undefined,
          momentType: undefined,
          name: undefined,
          detail: undefined,
          videoUrl: undefined,
          delFlag: undefined,
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.dynamicId)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加动态";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const dynamicId = row.dynamicId || this.ids
        getDynamic(dynamicId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改动态";
        });
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.dynamicId != undefined) {
              updateDynamic(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            } else {
              addDynamic(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const dynamicIds = row.dynamicId || this.ids;
        this.$confirm('是否确认删除动态编号为"' + dynamicIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDynamic(dynamicIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有动态数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDynamic(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      }
    }
  };
</script>
